import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Arithmetic {
	String formula = new String();
	int a = new Random().nextInt(4);
	int b = new Random().nextInt(10) % (10 - 1 + 1) + 1;
	int c = new Random().nextInt(10) % (10 - 2 + 1) + 2;
	int d = new Random().nextInt(10) % (10 - 1 + 1) + 1;
	int e = new Random().nextInt(10) % (10 - 2 + 1) + 2;
	int f = new Random().nextInt(100);
	int g = new Random().nextInt(100);
	int third = new Random().nextInt(100);
	String astr = "";
	String qstr = "";
//	boolean x;

	public Arithmetic() {
//		this.x = x;
		// System.out.println(a);
		// System.out.println(b);
		// System.out.println(c);
		// System.out.println(d);
		// System.out.println(e);
		// System.out.println(f);
		// System.out.println(g);
	}

	public String int_operation() {
		int result = 0;
		// if (a == 0)
		// result = f + g;
		// if (a == 1)
		// result = f - g;
		// if (a == 2)
		// result = f * g;
		// astr = String.valueOf(result);
		// if (a == 3) {
		// if (g == 0) {
//		astr = int_operation();
		// return astr;
		// } else {
		// if (g != 0 && g != 1) {
		// int d = common_divisor(f, g);
		// f = f / d;
		// g = g / d;
		// astr = (f + "/" + g);
		// }
		// if (g == 1)
		// astr = ("" + f);
		// }
		//
		// }
		String fh1 = fh_Random();
		String fh2 = fh_Random();
		formula = kh_Random(fh1, fh2);
		System.out.println(formula);
		Calculate(formula);
		return astr;
	}

	private String fh_Random() {
		int fh = new Random().nextInt(4);
		String fuhao = new String();
		switch (fh) {
		case 0:
			fuhao = "+";
			break;
		case 1:
			fuhao = "-";
			break;
		case 2:
			fuhao = "×";
			break;
		case 3:
			fuhao = "÷";
			break;
		}
		return fuhao;
	}

	private String kh_Random(String fh1, String fh2) {
		int flag = new Random().nextInt(3);
		f = new Random().nextInt(100);
		g = new Random().nextInt(100);
		third = new Random().nextInt(100);
		switch (flag) {
		case 0:
			formula =  f + fh1 + g + fh2 + third;
			break;
		case 1:
			formula = "(" + f + fh1 + g + ")" + fh2 + third;
			break;
		case 2:
			formula = f + fh1 + "(" + g + fh2 + third + ")";
			break;
		}
		return formula;
	}

	// public String fra_operation() {
	// this.b = new Random().nextInt(10) % (10 - 1 + 1) + 1;
	// this.c = new Random().nextInt(10) % (10 - 2 + 1) + 2;
	// this.d = new Random().nextInt(10) % (10 - 1 + 1) + 1;
	// this.e = new Random().nextInt(10) % (10 - 2 + 1) + 2;
	//
	// // System.out.println("a=" + a);
	// // System.out.println("b=" + b);
	// // System.out.println("c=" + c);
	// // System.out.println("d=" + d);
	// // System.out.println("e=" + e);
	// // System.out.println("f=" + f);
	// // System.out.println("g=" + g);
	//
	// if (c < b || e < d || c % b == 0 || e % d == 0) {
	// astr = fra_operation();
	// return astr;
	// }
	//
	// int fz = 1, fm = c * e;
	// if (a == 0)
	// fz = b * e + c * d;
	// if (a == 1) {
	// fz = b * e - c * d;
	// if (fz == 0) {
	// return astr = ("0");
	// }
	// }
	//
	// if (a == 2)
	// fz = b * d;
	// if (a == 3) {
	// fz = b * e;
	// fm = c * d;
	// }
	// int f = common_divisor(fm, fz);
	// if (f > 0) {
	// fm = fm / f;
	// fz = fz / f;
	// }
	// if (f < 0) {
	// fm = -fm / f;
	// fz = -fz / f;
	// }
	// astr = (fz + "/" + fm);
	// return astr;
	//
	// }

//	public static int common_divisor(int m, int n) {
//		while (m % n != 0) {
//			int t = m % n;
//			m = n;
//			n = t;
//		}
//		return n;
//	}

	public String toString() {
//		if (x == true) {
			// if (a == 0)
			// qstr = (f + "+" + g + "=");
			// if (a == 1)
			// qstr = (f + "-" + g + "=");
			// if (a == 2)
			// qstr = (f + "×" + g + "=");
			// if (a == 3)
			// qstr = (f + "÷" + g + "=");
			qstr = formula + "=";
//		}
//		if (x == false) {
//			if (a == 0)
//				qstr = (b + "/" + c + "+" + d + "/" + e + "=");
//			if (a == 1)
//				qstr = (b + "/" + c + "-" + d + "/" + e + "=");
//			if (a == 2)
//				qstr = (b + "/" + c + "×" + d + "/" + e + "=");
//			if (a == 3)
//				qstr = (b + "/" + c + "÷" + d + "/" + e + "=");
//		}
		return qstr;
	}
	
	public void Calculate(String formula) {
		Scanner in = new Scanner(formula);

		while (in.hasNextLine()) {
			String s = in.nextLine();

			try {
				List<Object> list = trans(s);

				Stack<Double> result = new Stack<Double>();
				double res = f(list, result);
				astr=res+"";
				System.out.println(astr);
			} catch (Exception e) {
				System.out.println("表达式不合法!");
			}
		}
	}

	private double f(List<Object> list, Stack<Double> result) {
		Iterator it = list.iterator();
		while (it.hasNext()) {
			String m = it.next().toString();
			if (m.equals("+") || m.equals("-") || m.equals("×") || m.equals("÷")) {
				double b = result.pop();

				double a = result.pop();
				double v = g(a, b, m);
				result.push(v);
			} else {
				result.push(Double.valueOf(m));
			}
		}
		return (result.pop());
	}

	private  double g(double a, double b, String m) {

		double v = 0;
		switch (m) {
		case "+":
			v = a + b;
			break;
		case "-":
			v = a - b;
			break;
		case "×":
			v = a * b;
			break;
		case "÷":
			v = a / b;
			break;
		}
		return v;

	}

	private  List<Object> trans(String s) {
		Stack<Character> op = new Stack<Character>();

		ArrayList<Object> list = new ArrayList<Object>();
		Pattern P = Pattern.compile("[0-9]+(\\.[0-9]+)?"); // 正则表达式来处理带小数点的数字
		int i = 0;

		while (i < s.length()) {
			char c = s.charAt(i);
			if (c >= '0' && c <= '9') {
				String s1 = s.substring(i);
				Matcher m = P.matcher(s1);
				if (m.find()) { // 取匹配到的第一个数字
					s1 = m.group();

					list.add(s1);
				}
				i = i + s1.length();
				continue;
			} else if (c == '(') {
				op.push(c);
			} else if (c == ')') {
				char p = op.pop();
				while (p != '(') {
					list.add(p);
					p = op.pop();
				}
			} else if (c == '+' || c == '-') {
				while (!op.isEmpty()
						&& (op.peek() == '+' || op.peek() == '-' || op.peek() == '×' || op.peek() == '÷')) {

					list.add(op.pop());
				}
				op.push(c);
			} else if (c == '×' || c == '÷') {
				while (!op.isEmpty() && (op.peek() == '×' || op.peek() == '÷')) {
					list.add(op.pop());
				}
				op.push(c);
			}
			i++;
		}

		while (!op.isEmpty()) {
			list.add(op.pop());
		}
		return list;
	}

}